package Model;

import JDBC.Constants;
import JDBC.DBConnection;


import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Zonas {

    public Zonas() {
    }

    public String[] selectAll() {
        DBConnection dbConection = new DBConnection(Constants.DB_NAME, Constants.USER, Constants.PASSWORD, false, null);

        String sql = "SELECT * FROM Zona";
        DBConnection.ConnectionHandler ch = new DBConnection.ConnectionHandler();
        dbConection.returnResultSetSelectStatement(sql, 1, ch);

        List<String> zonas = new ArrayList<String>();
        try {
            while(ch.r.next()) {
                String zona = ch.r.getString("designacao");
                zonas.add(zona);
            }
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            System.out.println("Zonas->selectAll() : " + e.getMessage());
        }

        return zonas.toArray(new String[0]);
    }
}
